<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>state</title>
  </head>
  <body>
    <div id="test">我是一段文本</div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>
    <script src="../js/prop-types.js"></script>

    <script type="text/babel">
      // 创建类式组件
      class Login extends React.Component {
        state = {
          name: 'name',
          psw: 'psw'
        }
        handleSubmit = (event) => {
          event.preventDefault()
          const { userName, password } = this
          alert(userName.value)
        }
        render() {
          const { name, psw } = this.state
          return (
            <form onSubmit={this.handleSubmit}>
              {/* 注意：这样写 label 进行 for 关联的时候，页面会报错，但不影响呈现 */}
              <label for={name}>用户名：</label>
              <input
                type="text"
                ref={(c) => (this.userName = c)}
                name={name}
                id={name}
                placeholder="user name"
              />
              <br />
              <label for="psw">密码：</label>
              <input
                type="password"
                ref={(c) => (this.password = c)}
                name={psw}
                id={psw}
                placeholder="password"
              />
              <br />
              <button>登录</button>
            </form>
          )
        }
      }

      ReactDOM.render(<Login />, document.getElementById('test'))
    </script>
  </body>
</html>
